/**
 * 拨打电话指令
 * 使用方式 v-phone="phonenumber"
 * @Prop phonenumber 电话号码
 */
import Vue from 'vue'
import { Message } from 'element-ui'
import { CtiModule } from '@/store/modules/cti/index'
const fun = (el, binding) => {
  const phone = binding.value
  const modifiers = binding.modifiers
  el.onclick = (e) => {
    if (modifiers.prevent) {
      e.preventDefault()
    }
    if (modifiers.stop) {
      e.stopPropagation()
    }
    CtiModule.CtiDialoutAction({ calleeNumber: phone }).then((res: any) => {
      if (res && res.success) {
        Message({ message: '外呼成功', type: 'success' })
      }
    })
  }
}

const phoneDriective = {
  bind: fun,
  update: fun
}

Vue.directive('phone', phoneDriective)
